/*  

Cafechess Library: Cover basic chess programming needs, like GUI, Engine integration, 
FEN and PGN parsing.

                 \\|//
                 (o o)
--------------ooO-(_)-Ooo----------------------------------
Copyright (C) 2009  By Gregory A. Prentice Snoqualmie, WA
                    www.cafechess.org
                    cafechess@comcast.net
                      Oooo
--------------oooO----(  )---------------------------------
              (  )    (_/
               \_)

Microsoft Public License (Ms-PL)

Revisions:

Author        Date    Description:

*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Cafechess.Forms
{
  public class UpdateProgressThreaded : UpdateThreaded
  {
    int coScale;
    long coCurrentUnits;
    int coIncrement;

    public int Increment
    {
      get { return coIncrement; }
      set { coIncrement = value; }
    }

    public long Count
    {
      get { return coCurrentUnits; }
    }
   
    public UpdateProgressThreaded(ProgressBar progress, int scale)
      : base(progress)
    {
      coScale = scale;
      coIncrement = 1;
    }

    public static UpdateProgressThreaded operator ++(UpdateProgressThreaded up)
    {
      up.coCurrentUnits += up.coIncrement;
      return up;
    }
    public static UpdateProgressThreaded operator --(UpdateProgressThreaded up)
    {
      up.coCurrentUnits -= up.coIncrement;
      return up;
    }
    /// <summary>
    /// Simply locks our control and resets its values.
    /// </summary>
    protected override void ResetUI()
    {
      lock (coControl)
      {
        ProgressBar progress = coControl as ProgressBar;
        progress.Value = 0;
        coCurrentUnits = 0;
      }
    }
    /// <summary>
    /// Lock our control and then update its display values.
    /// </summary>
    protected override void UpdateUI()
    {
      lock (coControl)
      {
        ProgressBar progress = coControl as ProgressBar;
        int total = (int)((coCurrentUnits / coScale) % progress.Maximum);
        //if (total == 0 && coCurrentUnits >= coScale)
        //  total = progress.Maximum;
        progress.Value = total;
      }
    }
  }
}
